﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using System.Data;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btLogin_Click(object sender, EventArgs e)
    {
        
        UserDAO userDao = new UserDAO();
        string strStuNum = this.tbStudyNum.Text;
        string strPwd = this.tbPwd.Text;
        DataSet ds = userDao.getUserByNameAndPwd(strStuNum, strPwd);

        // 分不同的权限跳向不同的地方
        if (ds.Tables[0].Rows.Count > 0)
        {
            string roleId = ds.Tables[0].Rows[0][1].ToString().Trim();
            switch(roleId)
            {
                    // 管理员
                case "1":
                    
                    break;
                    // 老师
                case "2":
                    Session["teacherId"] = ds.Tables[0].Rows[0][0].ToString().Trim();
                    Response.Redirect("~/Teacher/TeacherHomePage.aspx");
                    break;
                    // 学生
                case "3":
                    Session["studentId"] = ds.Tables[0].Rows[0][0].ToString().Trim();
                    Response.Redirect("~/Student/StudentHomePage.aspx");
                    break;
                    // 教学点
                case "4":

                    break;
            }
          
        }
        else
        {
            // Fail
            this.tbStudyNum.Text = "";
            this.tbPwd.Text = "";
        }
    }
    protected void btCancel_Click(object sender, EventArgs e)
    {
        this.tbStudyNum.Text = "";
        this.tbPwd.Text = "";
    }
    protected void tbPwd_TextChanged(object sender, EventArgs e)
    {

    }
}
